home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / ARCHIVES.SWG / 0016_archive detection.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  1KB  |  62 lines

  1. {
  2.  
  3.  RS>    Can anyone tell me where to find some source dealing with archive
  4.  RS> detection?  I need to be able to determine what archival method was used
  5.  RS> on a file regardless of the extension..
  6.  
  7. Yep.
  8.  
  9. BTW: I cut it out of a source I made it for. I should compile as is. you might
  10. have to "USES" dos and/or CRT.
  11.  
  12. ----------------------------= CUT HERE =-------------------------------------
  13. }
  14.  
  15. Type
  16.      ArchiveType = (ARJ,ZIP,UC2,LZH,UNKNOWN);
  17.  
  18. Function GetArchiveType (Name : String) : Archivetype;
  19. Var F : File;
  20.     Buf: Word;
  21.     StrBuf : String [3];
  22. Begin
  23.   GetArchiveType := UNKNOWN;
  24.   Assign (F,Name);
  25.   FileMode := 0;
  26.   Reset (F,1);
  27.   If IoResult <> 0 Then
  28.   Begin
  29.     Write ('Unable to access file - ');
  30.     WriteLn (Name);
  31.     Exit;
  32.   End;
  33.   BlockRead (F,Buf,2);
  34.   If Buf = $EA60 Then
  35.   Begin
  36.     GetArchiveType := ARJ;
  37.     Close (f);
  38.     Exit;
  39.   End;
  40.   If Buf = $4b50 Then
  41.   Begin
  42.     GetArchiveType := ZIP;
  43.     Close (f);
  44.     Exit;
  45.   End;
  46.   If Buf = $4355 Then
  47.   Begin
  48.     GetArchiveType := UC2;
  49.     Close (f);
  50.     Exit;
  51.   End;
  52.   BlockRead (F,StrBuf[1],3);
  53.   StrBuf[0] := #3;
  54.   If StrBuf = '-lh' Then
  55.   Begin
  56.     GetArchiveType := LZH;
  57.     Close (f);
  58.     Exit;
  59.   End;
  60. End;
  61.  
  62.